package ${package.ServiceImpl};

import ${package.Entity}.${entity};
import ${package.Mapper}.${table.mapperName};
<#if generateService>
import ${package.Service}.${table.serviceName};
</#if>
import ${superServiceImplClassPackage};
import org.springframework.stereotype.Service;
<#if serviceAutowireMapper>
import org.springframework.beans.factory.annotation.Autowired;
</#if>
<#if insertBatch>
import java.util.Collection;
<#elseif updateBatch>
import java.util.Collection;
</#if>
import java.util.Date;

/**
 * <p>
 * ${table.comment!} 服务实现类
 * </p>
 *
 * @author ${author}
 * @since ${date}
 */
@Service
<#if kotlin>
open class ${table.serviceImplName} : ${superServiceImplClass}<${table.mapperName}, ${entity}>()<#if generateService>, ${table.serviceName}</#if> {

}
<#else>
public class ${table.serviceImplName} extends ${superServiceImplClass}<${table.mapperName}, ${entity}><#if generateService> implements ${table.serviceName}</#if> {
     <#if serviceAutowireMapper>
         @Autowired
         protected ${table.mapperName} baseMapper;
     </#if>

     <#if insert>
         @Override
         public int insert(${entity} entity) {
             Date now = new Date();
             entity.setCreateTime(now);
             entity.setModifyTime(now);
             entity.setDeleted(false);
             entity.setVersion(1);
             return baseMapper.insert(entity);
         }
     </#if>

     <#if insertBatch>
         @Override
         public int insertBatch(Collection<${entity}> list) {
             if (list == null || list.isEmpty()) {
                 return 0;
             }
             Date now = new Date();
             for (${entity} entity : list) {
                 entity.setCreateTime(now);
                 entity.setModifyTime(now);
                 entity.setDeleted(false);
                 entity.setVersion(1);
             }
             return baseMapper.insertBatch(list);
         }
     </#if>

     <#if updateBatch>
         @Override
         public int updateBatch(Collection<${entity}> list) {
             if (list == null || list.isEmpty()) {
                 return 0;
             }
             return baseMapper.updateBatch(list);
         }
     </#if>
}
</#if>
